﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;

public partial class Admin_Default2 : System.Web.UI.Page
{
    clsDBOperation objDBOp = new clsDBOperation();
    Hashtable hstParameters = new Hashtable();
    DataSet dsadmin = new DataSet();


    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["dsGolbal"] == null)
        {
            Response.Redirect("../");
        }
        dsadmin = (DataSet)Session.Contents["dsGolbal"];

        if (!IsPostBack)
        {
            FillSMSCategory();
        }

    }

    private void FillSMSCategory()
    {

        try
        {
            DataSet dssave = new DataSet();
            hstParameters.Clear();
            hstParameters.Add("Action", "Fill_Game_Category");
            dssave = (DataSet)objDBOp.GetDataset("sp_SMS", CommandType.StoredProcedure, hstParameters);
            if (dssave.Tables.Count > 0 && dssave.Tables[0].Rows.Count > 0)
            {

                ddlSubCategory.DataTextField = "SubCategoryName";
                ddlSubCategory.DataValueField = "SubCategoryID";
                ddlSubCategory.DataSource = dssave;
                ddlSubCategory.DataBind();
                ddlSubCategory.Items.Insert(0, new ListItem("---Select SMS Category---", "0"));
            }
            else
            {
                ddlSubCategory.Items.Clear();
                ddlSubCategory.Items.Insert(0, new ListItem("---Not Record Found--- ", "0"));

            }

        }
        catch (Exception ex)
        {
            lblmsg.Text = "An Error Occure " + ex.Message.ToString();
            lblmsg.EnableViewState = false;
        }
    }


    protected void ddlSubCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        GetSMS();
    }

    private void GetSMS()
    {
        try
        {
            DataSet dssave = new DataSet();
            hstParameters.Clear();
            hstParameters.Add("Action", "Get_SMS");
            hstParameters.Add("FK_SubCategoryID", Convert.ToInt32(ddlSubCategory.SelectedValue));
            dssave = (DataSet)objDBOp.GetDataset("sp_SMS", CommandType.StoredProcedure, hstParameters);
            if (dssave.Tables.Count > 0 && dssave.Tables[0].Rows.Count > 0)
            {

                grdSMS.DataSource = dssave;
                grdSMS.DataBind();
                lblmsg.Text = string.Empty;
            }
            else
            {
                lblmsg.Text = "No Records Found For SMS Category " + ddlSubCategory.SelectedItem.Text;
                grdSMS.DataSource = null;
                grdSMS.DataBind();

            }
        }
        catch (Exception ex)
        {
            lblmsg.Text = "An Error Occure " + ex.Message.ToString();
            lblmsg.EnableViewState = false;
        }

    }
    protected void btnAddSMS_Click(object sender, EventArgs e)
    {
        Save();
        GetSMS();
    }

    private void Save()
    {
        try
        {
            //string PATH = Request.ServerVariables["APPL_PHYSICAL_PATH"].Trim();
            //string fileGameCover = Path.GetFileName(FileUploadGameCover.FileName);
            //FileUploadGameCover.SaveAs(PATH + "Admin/OnlineGameCover/" + fileGameCover);

            //string GamePATH = Request.ServerVariables["APPL_PHYSICAL_PATH"].Trim();
            //string fileGame = Path.GetFileName(FileUploadFlashGame.FileName);
            //FileUploadFlashGame.SaveAs(GamePATH + "Admin/OnlineGame/" + fileGame);


            int IsSaved;
            hstParameters.Clear();
            hstParameters.Add("Action", "Insert_SMS");
            hstParameters.Add("UserName", dsadmin.Tables[0].Rows[0][1].ToString());
            hstParameters.Add("FK_SubCategoryID", Convert.ToInt32(ddlSubCategory.SelectedValue));
            hstParameters.Add("SMS", FCKeditorSMS.Value);
            hstParameters.Add("SMSLanguage",txtSMSLanguage.Text);
            hstParameters.Add("SMSOwner", txtOwner.Text);

            IsSaved = Convert.ToInt32(objDBOp.ExecuteNonQuery("sp_SMS", CommandType.StoredProcedure, hstParameters));
            if (IsSaved > 0)
                lblmsg.Text = "Record Saved Successfully";
            FCKeditorSMS.Value = "";
        }
        catch (Exception ex)
        {
            lblmsg.Text = "An Error Occure " + ex.Message.ToString();
            lblmsg.EnableViewState = false;
        }
    }
}
